package com.jy.rhin.infra.repo.document.submission.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.jy.rhin.infra.repo.document.submission.po.DocumentFolderPO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author dhl
 * @date 2022/6/1
 * @Description
 */
@Mapper
@Repository
public interface DocumentFolderMapper extends BaseMapper<DocumentFolderPO> {
    /**
     * 列表查询
     * @param queryWrapper
     * @return
     */
    @Select("SELECT DISTINCT a.id,                                                   \n" +
            "       a.submission_id     AS submissionId,                             \n" +
            "       a.home_community_id AS homeCommunityId,                          \n" +
            "       a.patient_id        AS patientId,                                \n" +
            "       a.status_code       AS statusCode,                               \n" +
            "       a.unique_id         AS uniqueId,                                 \n" +
            "       a.last_update_time  AS lastUpdateTime                            \n" +
            "   FROM t_document_folder a ${ew.customSqlSegment}")
    List<DocumentFolderPO> queryDocumengFolderListByCoding(@Param(Constants.WRAPPER) QueryWrapper<DocumentFolderPO> queryWrapper);
    /**
     * 列表查询
     * @param queryWrapper
     * @return
     */
    @Select("SELECT DISTINCT DISTINCT a.id,                                                   \n" +
            "       a.submission_id     AS submissionId,                                      \n" +
            "       a.home_community_id AS homeCommunityId,                                   \n" +
            "       a.patient_id        AS patientId,                                         \n" +
            "       a.status_code       AS statusCode,                                        \n" +
            "       a.unique_id         AS uniqueId,                                          \n" +
            "       a.last_update_time  AS lastUpdateTime                                     \n" +
            "   FROM t_document_folder a left join t_document_entry b ON a.submission_id = b.submission_id     \n" +
            "${ew.customSqlSegment}")
    List<DocumentFolderPO> queryDocumentFolderListByEntry(@Param(Constants.WRAPPER) QueryWrapper<DocumentFolderPO> queryWrapper);
}
